<script>
    app.controller('UserUpdatePasswordCtrl', function ($scope, $http, $state) {
        $('#oldPassword').focus();

        $scope.updatePassword = function () {
            if ($scope.newPassword != $scope.confirmNewPassword) {
                new PNotify({
                    text: '新密码与确认密码不匹配',
                    addclass: 'bg-danger'
                });
                return;
            }

            $http.patch('r/users/update-password', {
                oldPassword: $scope.oldPassword,
                newPassword: $scope.newPassword
            }).success(function (data) {
                if (data.code < 300) {
                    new PNotify({
                        text: '密码修改成功'
                    });
                    $state.go('index');
                } else {
                    new PNotify({
                        text: data.reasonPhrase,
                        addclass: 'bg-danger'
                    });
                }
            });
        }
    });
</script>

<div class="panel panel-flat" ng-controller="UserUpdatePasswordCtrl">
    <div class="panel-heading">
        <h5 class="panel-title">修改密码</h5>
    </div>

    <div class="panel-body">
        <div class="col-md-6">
            <form ng-submit="updatePassword()">
                <div class="form-group">
                    <label>原密码</label>
                    <input id="oldPassword" type="password" ng-model="oldPassword" class="form-control" required>
                </div>
                <div class="form-group">
                    <label>新密码</label>
                    <input type="password" ng-model="newPassword" class="form-control" required>
                </div>
                <div class="form-group">
                    <label>确认密码</label>
                    <input type="password" ng-model="confirmNewPassword" class="form-control" required>
                </div>
                <div class="text-right">
                    <button type="submit" class="btn btn-primary">提 交<i
                            class="icon-arrow-right14 position-right"></i></button>
                </div>
            </form>
        </div>
    </div>
</div>
